<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
		<title>内容列表</title>
		<link rel="icon" href="favicon.ico" type="image/x-icon" />
		<jsp:include page="../include.jsp" />
		<style>
		.bar .site {
			float: right;
		}
		
		.select {
			margin-right: 20px;
		}
		
		#tree {
			float: left;
			width: 15%;
		}
		
		#table {
			float: right;
			width: 84%;
			border-left: 1px solid #CCCCCC;
		}
		
		#middle {
			padding: 0;
			float: left;
			width: 1px;
			background: #D8DEEA;
			height: 400px;
		}
		</style>
		<script type="text/javascript">
			$(document).ready(function(){
				  if(${fn:length(result)}==0){
					  $("#tree").css("display","none");
					  $("#middle").css("display","none");
					  $("#table").css("width","100%");
				  }
				  $("#model_id").change(function(){
				     if(this.value==-2){
						 window.location="../../modelAction/model/list.do";
						 return;
					 } 
					 if(this.value!=-1){
						 window.location="beforeAdd.do?site_id="+$("#site_id").val()+"&model_id="+$("#model_id").val()+"&model_type=2";
					 }
				  });
			});
			function edit(e){
				var url=e.attributes.url.value;
				window.location=url+"&site_id="+$("#site_id").val();
			}
			function deleteItem(e){
				
				var url=e.attributes.url.value;
				$.dialog({
							type : "warn",
							content : "确定要删除吗?",
							ok : "确 定",
							cancel : "取 消",
							modal : true,
							okCallback : deleteLine
						});
				function deleteLine() {
					$.ajax({
							url : url,
							type : "GET",
							dataType : "json",
							cache : false,
							success : function(data) {
								if (data.status == "success") {
									var tr=e.parentNode.parentNode;
									var table=e.parentNode.parentNode.parentNode;
									table.removeChild(tr);
								}
								$.message({
											type : data.status,
											content : data.message
										});
							}
						});
					}
			}
		</script>
	</head>
	<body class="list">
		<div class="bar">内容列表&nbsp;总记录数: ${pager.totalCount} (共${pager.pageCount}页)
			<div class="site">站点: 
				<select name="site_id" class="select" id="site_id">
					<c:forEach items="${sites}" var="site">
						<option value="${site.key}">${site.value}</option>
					</c:forEach>
				</select>
				内容模型: 
				<select name="model_id" class="select" id="model_id">
					<option value="-1">--选择模型--</option>
					<c:forEach items="${models}" var="model">
						<option value="${model.key}">${model.value}</option>
					</c:forEach>
					<c:if test="${fn:length(models)==0}">
						<option value="-2">添加模型</option>
					</c:if>
				</select>
			</div>
		</div>
		<div class="body">
			<form id="listForm" action="list.do" method="post">
				<div class="listBar">
					<label>查找: </label>
					<select name="searchBy">
						<option value="moduleName"> 
							名称
						</option>
					</select>
					<input type="text" name="keyword" value="${pager.keyword}" />
					<input type="button" id="searchButton" class="formButton" value="搜 索" hidefocus />
					&nbsp;&nbsp;
					<label>每页显示: </label>
					<select name="pageSize" id="pageSize">
						<option value="10"<c:if test="${pager.pageSize eq 10}"> selected="selected"</c:if>>
							10
						</option>
						<option value="1"<c:if test="${pager.pageSize eq 1}"> selected="selected"</c:if>>
							1
						</option>
						<option value="20"<c:if test="${pager.pageSize eq 20}"> selected="selected"</c:if>>
							20
						</option>
						<option value="50"<c:if test="${pager.pageSize eq 50}"> selected="selected"</c:if>>
							50
						</option>
						<option value="100"<c:if test="${pager.pageSize eq 100}"> selected="selected"</c:if>>
							100
						</option>
					</select>
				</div>
				<table id="listTable" class="listTable">
					<tr>
						<th class="check"><input type="checkbox" class="allCheck" /></th>
						<th><a href="#" class="sort" name="id" hidefocus>ID</a></th>
						<th><a href="#" class="sort" name="name" hidefocus>标题</a></th>
						<th><a href="#" class="sort" name="publish" hidefocus>发布者</a></th>
						<th><a href="#" class="sort" name="hit" hidefocus>点击</a></th>
						<th><a href="#" class="sort" name="date" hidefocus>发布时间</a></th>
						<th><a href="#" class="sort" name="state" hidefocus>状态</a></th>
						<th><span>操作</span></th>
					</tr>
					<c:forEach items="${pager.list}" var="content">
						<tr>
							<td><input type="checkbox" name="ids" value="${content.content_id}" /></td>
							<td>${content.content_id}</td>
							<td>${content.title}</td>
							<td>${content.author}</td>
							<td>${content.views}</td>
							<td>${content.release_date}</td>
							<td>${content.status}</td>
							<td>
								<a href="#" onclick="edit(this)" url="edit.do?id=${content.content_id}&model_id=${content.model_id}&model_type=2" title="修改">[修改]</a>
								<a href="#" onclick="deleteItem(this)" url="delete.do?ids=${content.content_id}" title="删除">[删除]</a>	
							</td>
						</tr>
					</c:forEach>
				</table>
				<c:choose>
					<c:when test="${fn:length(pager.list)!=0}">
						<div class="pagerBar">
							<div class="delete">
								<input type="button" id="deleteButton" class="formButton" url="delete.do" value="删除" disabled hidefocus />
							</div>
							<div class="pager">
								<jsp:include page="../common/pager.jsp" />
							</div>
						</div>
					</c:when>
					<c:otherwise>
						<div class="noRecord">没有找到任何记录!</div>
					</c:otherwise>
				</c:choose>
			</form>
		</div>
	</body>
</html>